#include <iostream>
#include <ctime>
#include <stack>
#include <string>

using namespace std;

int main(){
    stack<char> st;
    string s;
    bool tf=true;
    cout<<"Enter the parenthesis sequence ";
    getline(cin, s);
    for(int i = 0;i<s.size();i++){
        if(s[i]!='('&&s[i]!='['&&s[i]!='{'&&s[i]!='<'&&s[i]!='>'&&s[i]!='}'&&s[i]!=']'&&s[i]!=')'){
            s.erase(i,1);
            i--;
        }
    }
    if (s.length()%2==0){
        for(int i=0;i<s.length();i++)
        {   
            if(s[i] == '('||s[i]=='['||s[i]=='{'||s[i]=='<')
                st.push(s[i]);
            else{
                if((st.size()==0) || (s[i] == ')' && st.top() != '(') || (s[i] == ']' && st.top() != '[') || (
                    s[i] == '}' && st.top() != '{') || (s[i] == '>' && st.top() != '<')){
                        cout<<"False";
                        tf = false;
                        break;
                    }
            st.pop();
            }
        }
        if (tf==true && st.size()==0)
            cout<<"True";
    }
    else
        cout<<"False";
    return 0;
}